import {
  getClassListFun,
  updateClassInfoFun,
  updateInfoStatusFun,
} from "./services";
import { namespace } from "./configFile";
import { message } from "antd";

export default {
  namespace,
  state: {
    init: false,
    classList: [],
  },
  effects: {
    //课程列表
    *getClassList({ params }, { call, put }) {
      const request = yield call(getClassListFun, params);
      return {
        success: true,
        data: request.records,
        total: request.total,
      };
    },
    //更新课程信息
    *updateClassInfo({ params, callback }, { call, put }) {
      const request = yield call(updateClassInfoFun, params);
      if (request) {
        callback && callback();
      }
    },
    //更新课程状态
    *updateInfoStatus({ params, callback }, { call, put }) {
      const request = yield call(updateInfoStatusFun, params);
      if (request.code == 200) {
        callback && callback();
      } else {
        message.error(request.msg);
      }
    },
  },
  reducers: {
    save(state: any, { payload }: any) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
